package com.maoye.ossp.sys.att.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.att.entity.Attachment;
import com.maoye.ossp.sys.att.service.IAttService;
import com.maoye.ossp.sys.att.util.FileUtils;
import com.maoye.ossp.sys.base.utils.PropertyUtils;



@Controller
@RequestMapping(value = "/sys/att")
public class FileController  extends BaseController  {
	
	@Resource
	IAttService service;
	
	@Resource 
	FileUtils fileUtils;
	
	@RequestMapping("/test/{page}")
	public String test(@PathVariable("page") String page) {
		PropertyUtils.getContextProperty("");
		return "/sys/att/"+page;
	}
	
	/**
	 * 打开窗口
	 * @param response
	 * @return
	 * @throws IOException
	 * @author xiaohan
	 * @data 2014年3月28日
	 */
	@RequestMapping("/upload/dialog")
	public String tag(Attachment attachment,HttpServletResponse response) throws IOException {
		return "/sys/att/upload-dialog";
	}
	
	/**
	 * 查询列表
	 * @param response
	 * @author xiaohan
	 * @data 2014年3月28日
	 */
	@RequestMapping("/attr/download/list")
	public void getAttaByBillNo(Attachment attachment,HttpServletResponse response){
		service.findListByBill(attachment,response);
	}
	
	
	/**
	 * 上传文件处理
	 * @param attachment
	 * @param request
	 * @param response
	 * @throws IOException
	 * @author xiaohan
	 * @data 2014年3月26日
	 */
	@RequestMapping(value="/upload", method = RequestMethod.POST)
	public void upload(Attachment attachment, HttpServletRequest request, HttpServletResponse response) throws IOException {
		service.upload(attachment, request, response);
	}

	
	@RequestMapping(value="/getFile/{id}", method = RequestMethod.GET)
	public void getFile(@PathVariable("id")Long id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		service.getFile(id, response);
	}
	/**
	 * 删除文件
	 * 删除提示:<br>
{"files": [
  {
    "picture1.jpg": true
  },
  {
    "picture2.jpg": true
  }
]}
	 * @param request
	 * @param response
	 * @throws IOException
	 * @author eric
	 * @data 2014年1月25日
	 */
	@RequestMapping(value="/delFile/{id}", method = RequestMethod.GET)
	public void delFile(@PathVariable("id")Long id,HttpServletRequest request,HttpServletResponse response) throws IOException {
		service.delFile(id, response);
	}
	
	@RequestMapping(value="/getthumb", method = RequestMethod.GET)
	public void getthumb(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		service.getthumb(request, response);
	}
	
}
